﻿<?php
////get country list
function getCountryArray() {
    global $DB,$TABLE_COUNTRY;

    $aCountryOption = array();
    $sql = "SELECT CODE,NAME FROM $TABLE_COUNTRY ORDER BY CODE";
    $rset= $DB->query($sql);
    while ($row = $DB->fetchRow($rset)) {
        $aCountryOption[$row["CODE"]] = $row["NAME"];
    }
    $DB->freeResult($rset);
    return $aCountryOption;
}
//end

////get country name
function getCountryName($countryCode) {
    global $DB,$TABLE_COUNTRY;

    $sql = "SELECT NAME FROM $TABLE_COUNTRY WHERE CODE='".$countryCode."'";
    return $DB->getFirstField($sql);
}
//end

////get province list
function getProvinceArray($country) {
    global $DB,$TABLE_PROVINCE;

    $aProvinceOption = array();
    $sql = "SELECT ID,NAME,PROVINCECITY FROM $TABLE_PROVINCE WHERE COUNTRYCODE='".$country."'";
    $rset= $DB->query($sql);
    while ($row = $DB->fetchRow($rset)) {
        $aProvinceOption[$row["ID"]] = $row["NAME"];
    }
    $DB->freeResult($rset);
    return $aProvinceOption;
}
//end

////get province name
function getProvinceName($provinceID) {
    global $DB,$TABLE_PROVINCE;

    $sql = "SELECT NAME FROM $TABLE_PROVINCE WHERE ID='".$provinceID."'";
    return $DB->getFirstField($sql);
}
//end

////get city list
function getCityArray($province) {
    global $DB,$TABLE_CITY;

    $aCityOption = array();
    $sql = "SELECT ID,CODE,NAME FROM $TABLE_CITY WHERE PROVINCEID='".$province."'";
    $rset= $DB->query($sql);
    while ($row = $DB->fetchRow($rset)) {
        $aCityOption[$row["ID"]] = $row["NAME"];
    }
    $DB->freeResult($rset);
    return $aCityOption;
}
//end

////get city name
function getCityName($cityID) {
    global $DB,$TABLE_CITY;

    $sql = "SELECT NAME FROM $TABLE_CITY WHERE ID='".$cityID."'";
    return $DB->getFirstField($sql);
}
//end

////get county list
function getCountyArray($city) {
    global $DB,$TABLE_COUNTY;

    $aCountyOption = array();
    $sql = "SELECT ID,NAME,POSTCODE FROM $TABLE_COUNTY WHERE CITYID='".$city."'";
    $rset= $DB->query($sql);
    while ($row = $DB->fetchRow($rset)) {
        $aCountyOption[$row["ID"]] = $row["NAME"];
    }
    $DB->freeResult($rset);
    return $aCountyOption;
}
//end

////get county name
function getCountyName($countyID) {
    global $DB,$TABLE_COUNTY;

    $sql = "SELECT NAME FROM $TABLE_COUNTY WHERE ID='".$countyID."'";
    return $DB->getFirstField($sql);
}
//end

?>